<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <script>
    Promise.resolve = function(param) {
      console.log(param, 'param');
      if (param instanceof Promise) return param;
      return new Promise((resolve, reject) => {
        if (param && param.then && typeof param.then === 'function') {
          // param 状态变为成功会调用resolve，将新 Promise 的状态变为成功，反之亦然
          param.then(resolve, reject);
        } else {
          // 不是thenable对象，直接返回他的fulfilled
          resolve(param);
        }
      });
    }
    let p1 = Promise.resolve(new Error('123')) // 返回的仍旧是fulfilled状态
    let p2 = Promise.resolve(1)
    console.log(p1, 'p1');
    console.log(p2, 'p2');
    let p3 = new Promise((resolve, reject) => {
      reject(1)
    })
    let p4 = Promise.resolve(p3)
    console.log(p4, 'p4');
  </script>
</body>
</html>